% Initialize MOMshow with fixed width strings (18 characters per value)
MOMshow = cell(16, 1);  % Create cell array for display
MOMshow{1} = '';        % Version string will be set later
MOMshow{2} = 'Data Length     Telemetry Count  Valid Cmd Count  Error Cmd Count Latest Exec Code Device Serial   ';
MOMshow{3} = sprintf('%18d%18d%18d%18d%18d%18d', 0, 0, 0, 0, 0, 0);
MOMshow{4} = '';        % Empty line
MOMshow{5} = '';        % Empty line
MOMshow{6} = 'Work Mode       Power Enable     Temperature      Wheel Speed     A-Phase Current A-Phase Torque  ';
MOMshow{7} = sprintf('%18d%18d%18.6f%18.6f%18.6f%18.6f', 0, 0, 0, 0, 0, 0);
MOMshow{8} = '';        % Empty line
MOMshow{9} = '';        % Empty line
MOMshow{10} = 'Speed Target    Current Target   Torque Target   Reserved        Data Time       Subseconds      ';
MOMshow{11} = sprintf('%18d%18d%18d%18d%18d%18d', 0, 0, 0, 0, 0, 0);
MOMshow{12} = '';       % Empty line
MOMshow{13} = '';       % Empty line
MOMshow{14} = 'SUM Checksum         ';
MOMshow{15} = sprintf('%18d', 0);
MOMshow{16} = '';       % Empty line

% Create backup of display data
display_template = MOMshow;

% ... existing code ...

% Update rotation direction button text and colors
if get(handles.rotation_direction,'Value') == 0
    direction_text = 'Clockwise';
    set(handles.rotation_direction,'BackgroundColor',[0.8 0.8 1]);
else
    direction_text = 'Counter-clockwise';
    set(handles.rotation_direction,'BackgroundColor',[0.8 1 0.8]);
end

% --- Executes on button press in rotation_direction.
function rotation_direction_Callback(hObject, eventdata, handles)
% Get the current state of the toggle button
current_state = get(hObject, 'Value');

% Based on current state, determine which direction command to send
if current_state == 1
    % Button is pressed (on) - Send counter-clockwise command
    direction_cmd = '0A 1B 01 02 00 00 00 00'; % Counter-clockwise command (NN=02)
    direction_text = 'Counter-clockwise';
    log_msg = 'Sent counter-clockwise rotation command (0x02)';
    % Set background color to light green when button is pressed
    set(hObject, 'BackgroundColor', [0.8 1 0.8]); % Light green color
else
    % Button is unpressed (off) - Send clockwise command
    direction_cmd = '0A 1B 01 01 00 00 00 00'; % Clockwise command (NN=01)
    direction_text = 'Clockwise';
    log_msg = 'Sent clockwise rotation command (0x01)';
    % Set background color to light blue when showing clockwise rotation
    set(hObject, 'BackgroundColor', [0.8 0.8 1]); % Light blue color
end 